﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FreeGoo.GameEngine.Renderables.Links;

namespace FreeGoo.GameEngine.Renderables.Particles.States
{
    public class Sleeping : ParticleState
    {
        private const int WakeupFrequency = 50;

        public Sleeping(Particle particle)
            : base(particle)
        {
            ParticleSelectableInState = true;
        }

        public override void PerformStatePhysicsAction()
        {
            if (Engine.Random.Next(WakeupFrequency) == 1)
            {
                float wakeupReach = (float)(Particle.Radius * Particle.WakeupDistanceMultiplier * (0.5 + Engine.Random.NextDouble() * 0.5));
                IList<Link> closeLinks = Engine.GetLinksNearPosition(Particle.Position, wakeupReach, true);
                if (closeLinks.Count() > 0)
                {
                    Particle.IsSleeping = false;
                }
            }
        }
    }
}
